﻿@using BlazorAdmin.Client.TestPages.Components
@using Project.Constraints.Common.Attributes
@using Project.Constraints.Models.Permissions
@using Project.Constraints.Page
@using Project.Constraints.Services
@using Project.Web.Shared
@using Project.Web.Shared.ComponentHelper
@using Project.Web.Shared.Components
@using Project.Web.Shared.Utils
@using System.Diagnostics.CodeAnalysis
@inherits JsComponentBase
@page "/test"
@attribute [PageGroup("test", "测试", 5, Icon = "fa fa-question-circle-o")]
@attribute [PageInfo(Title = "Grid布局测试", Icon = "fa fa-question-circle-o", ForceShowOnNavMenu = true)]
@attribute [AutoLoadJsModule(Path = "TestPages")]
<MGrid MinWidth="300" Gap="10px">
    <MGridContent ColSpan="(1,3)" RowSpan="(1,3)">
        <div class="item" style="height:100%">123</div>
    </MGridContent>
    <div class="item">
        @UI.BuildButton(this).Text("Modal自定义Close").Primary().OnClick(OpenDialog).Render()
    </div>
    <div class="item">
        @UI.BuildButton(this).Text("异常测试").Primary().OnClick(ThrowException).Render()
    </div>
    <div class="item">
        @UI.BuildInput(this).Bind(() => input).Render()
    </div>
    <div class="item">
        @UI.BuildButton(this).Text("水印测试").Primary().OnClick(WaterMarkTest).Render()
    </div>
    <div class="item"></div>
    <div class="item">
        @UI.BuildButton(this).Text("ModalTest").Primary().OnClick(ShowModal).Render()
    </div>
    <div class="item">
        @UI.BuildButton(this).Text("JsOpen").Primary().OnClick(() => Js.OpenWindowAsync("")).Render()
    </div>
</MGrid>

<MModal @bind-Visible=visible Title="测试">
    <h1>Modal Content</h1>
</MModal>
@code {
    [Inject, NotNull] IDownloadServiceProvider? DownloadProvider { get; set; }
    [Inject, NotNull] IWatermarkServiceFactory? WatermarkServiceFactory { get; set; }
    string[] checkedUsers = [];
    bool visible;
    string input = "";

    Task Changed2(string[] values)
    {
        Console.WriteLine(string.Join(",", values ?? []));
        return Task.CompletedTask;
    }
    Task Changed()
    {
        Console.WriteLine(string.Join(",", checkedUsers ?? []));
        return Task.CompletedTask;
    }

    void ThrowException()
    {
        var div = 0;
        Console.WriteLine(1 / div);
    }

    void WaterMarkTest()
    {
        var service = WatermarkServiceFactory.GetWatermarkService();
        service.UpdateWaterMarkAsync(DateTime.Now.ToString("yyyy-MM-dd"), "测试");
    }

    async Task ShowModal()
    {
        var b = await UI.ConfirmAsync("测试", "ConfirmTest");
        if (b)
        {
            UI.AlertError("Test", "Content");
            visible = true;
        }
    }

    async Task OpenDialog()
    {
        await UI.ShowDialogAsync<DialogTest, int>(config: config =>
        {
            config.Title = "测试";
            config.ShowFooter = false;
        });
    }
}

@* <style> *@
@*     .item { *@
@*         border: solid 1px black; *@
@*         height: 300px; *@
@*     } *@
@* </style> *@
